package com.xmall.controller.admin;

import com.xmall.bean.vo.*;
import com.xmall.bean.bo.GoodsBO;
import com.xmall.bean.table.Goods;
import com.xmall.bean.table.GoodsAttribute;
import com.xmall.bean.table.GoodsProduct;
import com.xmall.bean.table.GoodsSpecification;
import com.xmall.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Connor
 * @ClassName: GoodsController
 * @PackageName: com.xmall.controller
 * @date 2020/12/06
 * @Version 1.0
 */

@RestController
@RequestMapping("/admin/goods")
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    @GetMapping("list")
    public BaseRespVo queryGoodsList(Integer page, Integer limit, Integer goodsSn, String name, String sort, String order) {
        GoodsListVO<Goods> goodsListVO = goodsService.queryGoodsList(page, limit, goodsSn, name, sort, order);
        return BaseRespVo.ok(goodsListVO);
    }

    @PostMapping("create")
    public BaseRespVo createGoods(@RequestBody GoodsBO<GoodsSpecification, GoodsProduct, GoodsAttribute> goodsBO) {
        goodsService.createGoods(goodsBO);
        return BaseRespVo.ok();
    }

    @PostMapping("update")
    public BaseRespVo updateGoods(@RequestBody GoodsBO<GoodsSpecification, GoodsProduct, GoodsAttribute> goodsBO) {
        goodsService.updateGoods(goodsBO);
        return BaseRespVo.ok();
    }

    @PostMapping("delete")
    public BaseRespVo deleteGoods(@RequestBody Goods goods) {
        goodsService.deleteGoods(goods);
        return BaseRespVo.ok();
    }

    @GetMapping("detail")
    public BaseRespVo queryGoodsDetail(Integer id) {
        GoodsDetailVO<GoodsAttribute, GoodsSpecification, GoodsProduct> goodsDetailVO = goodsService.queryGoodsDetail(id);
        return BaseRespVo.ok(goodsDetailVO);
    }

    @GetMapping("catAndBrand")
    public BaseRespVo queryCatAndBrand() {
        GoodsCatAndBrandVO<GoodsCategoryVO, GoodsBrandVO> goodsCatAndBrandVO = goodsService.queryGoodsCatAndBrand();
        return BaseRespVo.ok(goodsCatAndBrandVO);
    }

}
